﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebAsbesto.Usuarios
{
    public partial class UsuariosAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["User"] != "1")
                Response.Redirect("../Login/Login.aspx");
            else if (Session["User"] == "1")
            {
                //PAGE LOAD ACA!
                if (!IsPostBack)
                {
                  
                }
            }
        }

        protected void btn_Aceptar_Volver_Click(object sender, EventArgs e)
        {
            Grabar_BD();
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Ok", "alert('Usuario agregado con exito');", true);
            Page.Response.Redirect("Usuarios.aspx");
        }

        public void Limpiar_Formulario()
        {
            txt_Celular.Text = "";
            txt_Direccion.Text = "";
            txt_Email.Text = "";
            txt_Localidad.Text = "";
            txt_Pass.Text = "";
            txt_Telefono.Text = "";
            txt_Usuario.Text = "";
        }

        public bool Validar_Registros()
        {
            if (txt_Celular.Text != "" && txt_Direccion.Text != "" && txt_Email.Text != "" && txt_Localidad.Text != "" && txt_Pass.Text != "" && txt_Telefono.Text != "" && txt_Usuario.Text != "")
                return true;
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "Error", "alert('Debe Completar todos los campos Obligatorios');", true);
                return false;
            }
        }


        public void Grabar_BD()
        {
            if (Validar_Registros())
            {
                string Consulta;

                Consulta = "EXEC Usuarios_A '" + txt_Usuario.Text + "', '" + txt_Pass.Text + "', '" + txt_Direccion.Text + "', '" + txt_Localidad.Text + "', '" + txt_Telefono.Text + "', '" + txt_Celular.Text + "', '" + txt_Email.Text +"'";

                Funciones.Insert_DataBase(Consulta);
            }
        }

        protected void btn_Aceptar_Cargar_Otro_Click(object sender, EventArgs e)
        {
            Grabar_BD();
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Ok", "alert('Usuario agregado con exito');", true);
            Page.Response.Redirect("Usuarios.aspx");
        }
    }
}